package com.yjy.login.web;

import com.yjy.login.entity.LoginUser;
import com.yjy.login.hadler.AbstractHandler;
import com.yjy.login.hadler.VerifyAccountHandler;
import com.yjy.login.hadler.VerifyPermissionHanlder;
import com.yjy.login.hadler.VerifyRoleHanlder;

public class Client {
    public static void main(String[] args) {
        // 方式2：建造者模式+责任链模式
        AbstractHandler handler = new AbstractHandler.Builder()
                .add(new VerifyAccountHandler())
                .add(new VerifyRoleHanlder())
                .add(new VerifyPermissionHanlder()).build();

        System.out.println(">>>>>>>>测试1：全部通过 start<<<<<<<<<");
        LoginUser user1 = new LoginUser("TestAA", "123", "admin", "admin");
        handler.handle(user1);
        System.out.println(">>>>>>>>测试1：全部通过 end<<<<<<<<<");
        System.out.println();

        System.out.println(">>>>>>>>测试2：用户名为空 start<<<<<<<<<");
        LoginUser user2 = new LoginUser("", "123", "admin", "admin");
        handler.handle(user2);
        System.out.println(">>>>>>>>测试2：用户名为空 end<<<<<<<<<");
        System.out.println();

        System.out.println(">>>>>>>>测试3：密码不正确 start<<<<<<<<<");
        LoginUser user3 = new LoginUser("TestAA", "12345", "admin", "admin");
        handler.handle(user3);
        System.out.println(">>>>>>>>测试3：密码不正确 end<<<<<<<<<");
        System.out.println();

        System.out.println(">>>>>>>>测试4：角色不允许访问 start<<<<<<<<<");
        LoginUser user4 = new LoginUser("TestAA", "123", "user", "user");
        handler.handle(user4);
        System.out.println(">>>>>>>>测试4：角色不允许访问 end<<<<<<<<<");
        System.out.println();

        System.out.println(">>>>>>>>测试5：权限不允许访问 start<<<<<<<<<");
        LoginUser user5 = new LoginUser("TestAA", "123", "admin", "user");
        handler.handle(user5);
        System.out.println(">>>>>>>>测试5：权限不允许访问 end<<<<<<<<<");
        System.out.println();

    }
}
